package com.mep.rbac.controller;

import cn.hutool.core.util.StrUtil;
import com.mep.common.http.HttpResult;
import com.mep.rbac.feign.IFeignUserApi;
import io.jsonwebtoken.Jwts;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets;

@Api(value="001-oauth2--user的controller",tags="001-oauth2--user的controller")
@RestController
@RequestMapping("/user")
public class UserController implements IFeignUserApi {

    @Override
    @ApiOperation(value="01.获得auth2用户认证信息",notes="问题点:获得auth2用户认证信息")
    @ApiOperationSupport(order = 1, author = "lyl")
    //@PostMapping("/getCurrentUser")
    public HttpResult getCurrentUser(HttpServletRequest request) {
        String header = request.getHeader("Authorization");
        String token = StrUtil.subAfter(header, "bearer", false);

        Object ss = Jwts.parser()
                .setSigningKey("test_key".getBytes(StandardCharsets.UTF_8))
                .parseClaimsJws(token)
                .getBody();
        return HttpResult.ok(ss);
    }
}

